package com.example.educationalsystem.common.security.handler;

import com.example.educationalsystem.common.util.ResponseJson;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 登出成功处理类
 */
@Component
public class UserLogoutSuccessHandler implements LogoutSuccessHandler {
    /**
     * 用户登出返回结果
     * 这里应该让前端清除掉Token
     */
    @Override
    public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication){

        ResponseJson responseJson = new ResponseJson();
        responseJson.setStatus(200);
        responseJson.setMsg("登出成功");
        SecurityContextHolder.clearContext();    //清除上下文
        ResponseJson.responsHandlerJson(response,responseJson);

    }

}
